package com.pipayshop.controller;


import com.pipayshop.entity.BuyerData;
import com.pipayshop.entity.UserWithdrawal;
import com.pipayshop.entity.vo.ResponseVO;
import com.pipayshop.exception.BusinessException;
import com.pipayshop.service.BuyerDataService;
import com.pipayshop.service.UserWithdrawalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 买家的收货地址（多选） 前端控制器
 * </p>
 *
 * @author nws
 * @since 2023-07-25
 */
@Api(value = "用户提现接口",tags = "用户提现接口")
@RestController
@RequestMapping("/pipayshopapi/user-withdrawal")
public class UserWithdrawalController {
    @Resource
    private UserWithdrawalService userWithdrawalService;

    @GetMapping("selectAll")
    @ApiOperation("根据用户Id查找用户的提现记录")
    public ResponseVO<List<UserWithdrawal>> selectAll(){
        try {
            List<UserWithdrawal> list = userWithdrawalService.selectAll();
            return ResponseVO.getSuccessResponseVo(list);
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("user_shipping_address_lookup_failed");
        }
    }

    @GetMapping("get/{userId}")
    @ApiOperation("根据用户Id查找用户的提现记录")
    public ResponseVO get(@PathVariable Integer userId){
        try {
            List<UserWithdrawal> userWithdrawal = userWithdrawalService.selectByUserId(userId);
            return ResponseVO.getSuccessResponseVo(userWithdrawal);
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("user_shipping_address_lookup_failed");
        }
    }

    @GetMapping("updateById/{id}")
    @ApiOperation("根据用户Id更改提现金额")
    public ResponseVO updateById(@PathVariable Long id){
        try {
            boolean result = userWithdrawalService.updateByStateId(id);
            if (!result) {
                throw new Exception();
            }
            return ResponseVO.getSuccessResponseVo("Chang_the_withdrawal_amount_according_to_the_user_Id_succeeded");
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("Failed_to_change_withdrawal_amount_based_on_user_Id");
        }
    }

    @PostMapping("insect")
    @ApiOperation("插入用户申请提现数据")
    public ResponseVO insectBuyerData(@RequestBody UserWithdrawal userWithdrawal){
        try {
            boolean result = userWithdrawalService.insect(userWithdrawal);
            if (!result){
                throw new Exception();
            }
            return ResponseVO.getSuccessResponseVo("Succeeded_in_inserting_the_user's_withdrawal_request_data");
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("Failed_to_insert_the_user's_withdrawal_data");
        }
    }


    @PostMapping("deleteById/{id}")
    @ApiOperation("根据id删除用户提现数据")
    public ResponseVO deleteById(@PathVariable Long id){
        try {
            boolean result = userWithdrawalService.deleteById(id);
            if (!result){
                throw new Exception();
            }
            return ResponseVO.getSuccessResponseVo("Succeeded_in_deleting_the_user_withdrawal_data_based_on_the_id");
        }catch (Exception e){
            e.printStackTrace();
            throw new BusinessException("Description_Failed_to_delete_user_withdrawal_data_based_on_id");
        }
    }

}
